﻿using FastDev;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class MyAgent : GoapAgent
{
    public Slider curProcessSlider;

    public Slider curHPSlider;

    public Text text;

    public int MaxHP = 100;
    public float CurHP;

    public List<GoapAction> curGoapActions = new List<GoapAction>();

    public override GoapAction Goal { get ; protected set ; }
    public override List<GoapAction> GoapActions { get ; protected set; }

    void Start()
    {
        GoapActions.Add(new CollectStone(this));
        GoapActions.Add(new CollectWood(this));
        GoapActions.Add(new ProcessTool(this));
        GoapActions.Add(new ProcessWood(this));
        GoapActions.Add(new ShopAction(this));
        GoapActions.Add(new SleepAction(this));

        Goal = new ProcessTool(this);

        StartPlan();
    }

    public override void OnActionFailed(GoapAction goapAction)
    {
        base.OnActionFailed(goapAction);

        StartPlan();
    }

    public override void OnPlanDone()
    {
        base.OnPlanDone();


        StartPlan();
    }

    public override void OnPlanFailed(string actionName)
    {
        base.OnPlanFailed(actionName);

        curGoapActions.RemoveAll((a) => a.Name == actionName);

        StartPlan();
    }

    protected override void Update()
    {
        base.Update();

        if (CurAction != null)
        {
            curProcessSlider.value = CurAction.Progress;
        }
        curHPSlider.value = GoapState.GetValue(AIStateKey.HP) / 100;
    }
}
